home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / base / netkit-b.07a / netkit-b / NetKit-B-0.07A / talk / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  5.1 KB  |  192 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. /*
  35.  * From: @(#)display.c    5.4 (Berkeley) 6/1/90
  36.  */
  37. char display_rcsid[] = 
  38.   "$Id: display.c,v 1.2 1996/07/16 03:30:46 dholland Exp $";
  39.  
  40. /*
  41.  * The window 'manager', initializes curses and handles the actual
  42.  * displaying of text
  43.  */
  44. #include "talk.h"
  45.  
  46. static void xscroll(xwin_t *win, int flag);
  47. static int readwin(WINDOW *win, int line, int col);
  48.  
  49. xwin_t    my_win;
  50. xwin_t    his_win;
  51. WINDOW    *line_win;
  52.  
  53. int    curses_initialized = 0;
  54.  
  55. /*
  56.  * max HAS to be a function, it is called with
  57.  * a argument of the form --foo at least once.
  58.  */
  59. int
  60. max(int a, int b)
  61. {
  62.  
  63.     return (a > b ? a : b);
  64. }
  65.  
  66. /*
  67.  * Display some text on somebody's window, processing some control
  68.  * characters while we are at it.
  69.  */
  70. void
  71. display(xwin_t *win, char *text, int size)
  72. {
  73.     register int i;
  74.     char cch;
  75.  
  76.     for (i = 0; i < size; i++) {
  77.         if (*text == '\n') {
  78.             xscroll(win, 0);
  79.             text++;
  80.             continue;
  81.         }
  82.         /* erase character */
  83.         if (*text == win->cerase) {
  84.             wmove(win->x_win, win->x_line, max(--win->x_col, 0));
  85.             getyx(win->x_win, win->x_line, win->x_col);
  86.             waddch(win->x_win, ' ');
  87.             wmove(win->x_win, win->x_line, win->x_col);
  88.             getyx(win->x_win, win->x_line, win->x_col);
  89.             text++;
  90.             continue;
  91.         }
  92.         /*
  93.          * On word erase search backwards until we find
  94.          * the beginning of a word or the beginning of
  95.          * the line.
  96.          */
  97.         if (*text == win->werase) {
  98.             int endcol, xcol, i, c;
  99.  
  100.             endcol = win->x_col;
  101.             xcol = endcol - 1;
  102.             while (xcol >= 0) {
  103.                 c = readwin(win->x_win, win->x_line, xcol);
  104.                 if (c != ' ')
  105.                     break;
  106.                 xcol--;
  107.             }
  108.             while (xcol >= 0) {
  109.                 c = readwin(win->x_win, win->x_line, xcol);
  110.                 if (c == ' ')
  111.                     break;
  112.                 xcol--;
  113.             }
  114.             wmove(win->x_win, win->x_line, xcol + 1);
  115.             for (i = xcol + 1; i < endcol; i++)
  116.                 waddch(win->x_win, ' ');
  117.             wmove(win->x_win, win->x_line, xcol + 1);
  118.             getyx(win->x_win, win->x_line, win->x_col);
  119.             continue;
  120.         }
  121.         /* line kill */
  122.         if (*text == win->kill) {
  123.             wmove(win->x_win, win->x_line, 0);
  124.             wclrtoeol(win->x_win);
  125.             getyx(win->x_win, win->x_line, win->x_col);
  126.             text++;
  127.             continue;
  128.         }
  129.         if (*text == '\f') {
  130.             if (win == &my_win)
  131.                 wrefresh(curscr);
  132.             text++;
  133.             continue;
  134.         }
  135.         if (win->x_col == COLS-1) {
  136.             /* check for wraparound */
  137.             xscroll(win, 0);
  138.         }
  139.         if (*text < ' ' && *text != '\t') {
  140.             waddch(win->x_win, '^');
  141.             getyx(win->x_win, win->x_line, win->x_col);
  142.             if (win->x_col == COLS-1) /* check for wraparound */
  143.                 xscroll(win, 0);
  144.             cch = (*text & 63) + 64;
  145.             waddch(win->x_win, cch);
  146.         } else
  147.             waddch(win->x_win, *text);
  148.         getyx(win->x_win, win->x_line, win->x_col);
  149.         text++;
  150.     }
  151.     wrefresh(win->x_win);
  152. }
  153.  
  154. /*
  155.  * Read the character at the indicated position in win
  156.  */
  157. static int
  158. readwin(WINDOW *win, int line, int col)
  159. {
  160.     int oldline, oldcol;
  161.     register int c;
  162.  
  163.     getyx(win, oldline, oldcol);
  164.     wmove(win, line, col);
  165.     c = winch(win);
  166.     wmove(win, oldline, oldcol);
  167.     return (c);
  168. }
  169.  
  170. /*
  171.  * Scroll a window, blanking out the line following the current line
  172.  * so that the current position is obvious
  173.  */
  174. static void
  175. xscroll(xwin_t *win, int flag)
  176. {
  177.  
  178.     if (flag == -1) {
  179.         wmove(win->x_win, 0, 0);
  180.         win->x_line = 0;
  181.         win->x_col = 0;
  182.         return;
  183.     }
  184.     win->x_line = (win->x_line + 1) % win->x_nlines;
  185.     win->x_col = 0;
  186.     wmove(win->x_win, win->x_line, win->x_col);
  187.     wclrtoeol(win->x_win);
  188.     wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
  189.     wclrtoeol(win->x_win);
  190.     wmove(win->x_win, win->x_line, win->x_col);
  191. }
  192.